package com.videoweb.service.impl;

import com.videoweb.entity.VideoComment;
import com.videoweb.entity.dto.VideoCommentDTO;
import com.videoweb.entity.response.AuditResponse;
import com.videoweb.mapper.VideoCommentMapper;
import com.videoweb.service.IVideoCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.videoweb.service.VideoAuditService.TextAuditService;
import com.videoweb.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lmr
 * @since 2025-05-17
 */
@Service
public class VideoCommentServiceImpl extends ServiceImpl<VideoCommentMapper, VideoComment> implements IVideoCommentService {


    @Autowired
    VideoCommentMapper videoCommentMapper;
@Autowired
    TextAuditService textAuditService;


    @Override
    public List<VideoComment> findAllComment() {
        return videoCommentMapper.selectList(null);
    }

    @Override
    public List<VideoCommentDTO> findCommentByVideoId(Long videoId) {
        return videoCommentMapper.getVideoCommentByVideoId(videoId);
    }

    @Override
    public int addComment(VideoComment comment) {

        Long userId = SecurityUtils.getUserId();
        comment.setUserId(userId);
        int row = videoCommentMapper.insert(comment);
        return row;
    }

    @Override
    public AuditResponse auditComment(String content) {
        AuditResponse auditResponse = textAuditService.audit(content);
        return auditResponse;
    }


    @Override
    public int delCommentById(Long commentId) {

        int row =videoCommentMapper.deleteById(commentId);
        return row;
    }


}
